{include file="public/header" /}
<link rel="stylesheet" href="/static/index/css/vant.css">
<style>
    .addSex {
        height: 100%;
    }
</style>
<body class="bgc">
<div class="header">
    <i class="layui-icon layui-icon-left"></i> 地址管理
</div>
<ul class="address-list" id="address">
    {foreach name="list" item="vo"}
    <li>

        <van-swipe-cell>
            <div class="address-only">
                <div class="flex-layout">
                    <div class="left">{$vo.nickname} {$vo.tel}
                        {if $vo.default == 1}<p>默认</p>{/if}
                    </div>
                    <img data-id="{$vo.id}" src="/static/index/img/edit.png" alt="" class="edit">
                </div>
                <div>{$vo.p.title}{$vo.c.title}{$vo.d.title}{$vo.details}</div>
            </div>
            <template #right>
                <van-button square type="danger" text="删除" data-id="{$vo.id}" class="address-del addSex"/>
            </template>
        </van-swipe-cell>
    </li>
    {/foreach}
</ul>

<p class="save save-fixed upd-save" onclick="load_href('{:url(\'address/add\')}',2)">+ 添加收货地址</p>
</body>
{include file="public/footer"/}
<script src="/static/index/js/vue.js"></script>
<script src="/static/index/js/vant.js"></script>

<script>
    new Vue({
        el: "#address",
        methods: {},
    })
    $('.choice').click(function (e) {
        var id = $(this).attr('data-id');
        _ajax('{:url("address/choice")}', {id: id});
    })
    $('.address-del').click(function (e) {
        layer.confirm('确定要删除当前地址吗？', {title: '请确认'}, function (index) {
            _ajax('{:url("address/delete")}',{id:e.currentTarget.dataset.id});
        });
    })
    $('.edit').click(function (e){
        location.href = "{:url(\'address/edit\')}?id="+e.currentTarget.dataset.id;
    })
    $(".pay-footer").click(function () {
        if (window.name != '') {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            parent.window.location.href = "{:url('address/index')}";
        } else {
            window.location.reload();
        }
    });
</script>
</html>